// GummyBear ^_^
// main.cpp

#include <stdlib.h>
#include <iostream>
#include <string>

#include "sqlparser.h"
#include "command.h"
#include "curDB.h"

void hellosql() {
  std::cout << "Welcome to use GummySQL. " << std::endl;
}

void readCommand(std::string *strcommand) {
  std::cout << std::endl << "> ";

  // Read the whole line.
  std::getline(std::cin, *strcommand);
}

void goodbyesql() {
  std::cout << "Good bye." << std::endl;
}

int main()
{
  // Say hello to the users.
  hellosql();

  // <strcommand> will record the command.
  std::string strcommand;

  while (1) {

    if (curDB.length() == 0) 
      std::cout << "(Please enter a database first. Or create one.)" << std::endl;

    // Read test;
    readCommand(&strcommand);

    // Exit.
    if (!strcommand.compare("exit")) {
      break;
    }

    // Clear;
    if (!strcommand.compare("clear")) { 
      system("clear");
      continue;
    } 

//---------------------------testing-----------------
    sqlParser parser;
    command *cmd;
    cmd = parser.excecute(strcommand);
      if (cmd != nullptr) cmd->excecute();
//-------------------------test-end-------------------

    // Use SQL parser to identify the command;
    // Todo

    // Create a database;
    // Todo

    // Delete a database;
    // Todo

    // Log in / Switch to another databse;
    // Todo
  }

  goodbyesql();
  return 0;
}